package a;

import t1.IAdd;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * Created by Administrator on 2018/1/20.
 */
public class B {

    public static void main(String[] args) throws Exception {
        String jarFilePath = "file:/F:/workspace/ideawp/hotLoadClassDemon/target/hotLoadClass-1.0-SNAPSHOT.jar";
        URL jarUrl = new File(jarFilePath).toURI().toURL();
        URL[] urls = new URL[] { jarUrl };
        URLClassLoader cl = new URLClassLoader(urls);

        String className = "t1.Add";
        Class<?> clazz = cl.loadClass(className);
        System.out.println("loadclass :"+clazz);
        IAdd add = (IAdd) clazz.newInstance();
        System.out.println(add.add(1,2));


        Thread.sleep(30*1000);

        urls = new URL[] { jarUrl };
        cl = new URLClassLoader(urls);
        Class<?> clazz2 = cl.loadClass(className);
        System.out.println("loadclass :"+clazz2);
        IAdd add2 = (IAdd) clazz2.newInstance();
        System.out.println(add2.add(1,2));


    }
}
